package com.zmcc.service.impl;

import com.google.gson.Gson;
import com.zmcc.entity.*;
import com.zmcc.entity.common.CommonRequest;
import com.zmcc.service.IVideoMsgRequest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class VideoMsgRequestCommercial implements IVideoMsgRequest {
    private final static String url = "https://dev.cmccopen.cn/api";

    private static VideoMsgRequestCommercial videoMsgRequestCommercial;

    public static VideoMsgRequestCommercial getInstance() {
        if (videoMsgRequestCommercial == null) {
            videoMsgRequestCommercial = new VideoMsgRequestCommercial();
        }
        return videoMsgRequestCommercial;
    }

    @Override
    public CommonRequest getTemplateAddSendRequest(VideoMsgTemplate template) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/videomsg" +"/template" +"/add");
        request.setBody(new Gson().toJson(template));
        return request;
    }

    @Override
    public CommonRequest getTemplateStatusQueryRequest(String templateId) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/videomsg" +"/template" +"/add");
        Map<String, String> bodyMap = new HashMap<>();
        bodyMap.put("templateId",templateId);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getVarFileAddSendRequest(String templateId,String fileContent) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("templateId",templateId);
        map.put("fileContent",fileContent);
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/videomsg" +"/variable" +"/add");
        request.setBody(new Gson().toJson(map));
        return request;
    }

    @Override
    public CommonRequest getVarFileStatusQueryRequest(String templateId, String varFileId) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("templateId",templateId);
        map.put("varFileId",varFileId);
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/videomsg" +"/variable" +"/status");
        request.setBody(new Gson().toJson(map));
        return request;
    }

    @Override
    public CommonRequest getSendVideoMsgRequest(VideoMsgSendTemplate template) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/videomsg" +"/send" +"/sms");
        request.setBody(new Gson().toJson(template));
        return request;
    }

    @Override
    public CommonRequest getDeliveryStatusRequest(String msgId,List<Mobile> mobiles) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("msgId",msgId);
        map.put("mobiles",mobiles);
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/videomsg" +"/deliveryStatus");
        request.setBody(new Gson().toJson(map));
        return request;
    }

    @Override
    public CommonRequest getSubscribeRequest(String flg,String san,String smsURL ) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("flg",flg);
        map.put("san",san);
        map.put("smsURL",smsURL);
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/videomsg" +"/subscribe");
        request.setBody(new Gson().toJson(map));
        return request;
    }

    @Override
    public CommonRequest getAddSignnatureRequest(List<Signature> signatureList) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("signatureList",signatureList);
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/videomsg" +"/signature"+"/add");
        request.setBody(new Gson().toJson(map));
        return request;
    }

    @Override
    public CommonRequest getDelSignnatureRequest(List<SignatureElement> signatureList) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("signatureList",signatureList);
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/videomsg" +"/signature"+"/del");
        request.setBody(new Gson().toJson(map));
        return request;
    }

}
